<?php

namespace app\api\controller;

use app\api\model\Brand as BrandModel;
use app\api\model\Config as ConfigModel;
use app\api\model\SystemConfig;
use app\api\model\UserCar as UserCarModel;
use app\common\controller\Api;
use think\Db;
use app\api\model\UserShop as UsershopModel;
use app\api\model\Goods as GoodsModel;
use app\api\model\User as UserModel;
use wxpay\Vehicle;

/**
 * 首页接口
 */
class Daoru extends Api
{
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];

   public function index()
   {
       die();
       $models = new Vehicle();
       $changpai = $models->changpai();
       halt($changpai);
       $time = time();
       foreach($changpai as $changpai_key => $changpai_val)
       {
           $changpai_id = \think\Db::name('vehicle')->insertGetId([
               'pid'  => 0,
               'level' => 1,
               'create_time' => $time,
               'first' => $changpai_val['initLetter'],
               'mergename' => $changpai_val['name'],
               'flag' => 'nohot',
               'logo' => $changpai_val['logo'],
               'pids' => 0
           ]);
           $chexing = $models->chexing($changpai_val['fullName']);
            // 添加车型
           foreach($chexing as $chexing_k => $chexing_v){
               $chexing_id = \think\Db::name('vehicle')->insertGetId([
                   'pid'  => $changpai_id,
                   'level' => 2,
                   'create_time' => $time,
                   'first' => $changpai_val['initLetter'],
                   'mergename' => $chexing_v['name'],
                   'flag' => 'nohot',
                   'pids' => '0'.'-'.$changpai_id
               ]);
               // 查看排量
               $pailiang = $models->pailiang($chexing_v['code']);
               foreach($pailiang as $pailiang_k => $pailiang_v)
               {
                   // 查看年份
                   $nianfen = $models->nianfen($chexing_v['code'],$pailiang_v);
                   foreach($nianfen as $nianfen_k => $nianfen_v){
                       $nianfen_pid = \think\Db::name('vehicle')->insertGetId([
                           'pid' => $chexing_id,
                           'level' => 3,
                           'create_time' => $time,
                           'first' => $changpai_val['initLetter'],
                           'mergename' => $nianfen_v,
                           'flag' => 'nohot',
                           'pids' => '0'.'-'.$changpai_id.'-'.$chexing_id
                       ]);
                       $pailiang_pid = \think\Db::name('vehicle')->insertGetId([
                           'pid' => $nianfen_pid,
                           'level' => 4,
                           'create_time' => $time,
                           'first' => $changpai_val['initLetter'],
                           'mergename' => $pailiang_v,
                           'flag' => 'nohot',
                           'pids' => '0'.'-'.$changpai_id.'-'.$chexing_id.'-'.$nianfen_pid
                       ]);
                       // 款型
                       $kuanxing = $models->kuanxing($chexing_v['code'],$pailiang_v,$nianfen_v);
                       foreach($kuanxing as $kuanxing_k => $kuanxing_v){
                           $id = \think\Db::name('vehicle')->insertGetId([
                               'pid'   => $pailiang_pid,
                               'level' => 5,
                               'create_time' => $time,
                               'first' => $changpai_val['initLetter'],
                               'mergename' => $kuanxing_v['displayName'],
                               'flag'  => 'nohot',
                               'pids'  => '0'.'-'.$changpai_id.'-'.$chexing_id.'-'.$nianfen_pid.'-'.$pailiang_pid
                           ]);
                       }
                   }
               }
           }
       }

   }

}
